package edu.jd.movieplatform.security.c_admin;

import edu.jd.movieplatform.common.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController //说明这是一个受spring容器管理的控制器组件(Bean)
@RequestMapping("/security/c_admin") //本控制器的路径前缀
public class CAdminAPI {
    //引入依赖对象
    @Resource //此注解表示从容器中引入依赖对象
    private CAdminService cAdminService;

    @GetMapping("")
    public Result queryCAdmins(CAdminDto dto){
        Map<String,Object> page =  cAdminService.getCAdminPage(dto);
        return Result.success(page);
    }
    @GetMapping("/nocinema")
    public Result queryNoCinemaCAdmins(CAdminDto dto){
        Map<String,Object> page =  cAdminService.getNoCinemaCAdminPage(dto);
        return Result.success(page);
    }

    @GetMapping("/{m_id}")
    public Result queryCAdminById(@PathVariable String m_id){
        CAdmin admin =  cAdminService.getCAdminById(m_id);
        return Result.success(admin);
    }


    @PostMapping("")
    public Result addCAdmin(@RequestBody CAdminDto dto){
        cAdminService.addCAdmin(dto);
        return Result.success();
    }

    @PutMapping("")
    public Result updateCAdmin(@RequestBody CAdminDto dto){
        cAdminService.updateCAdmin(dto);
        return Result.success();
    }

    @DeleteMapping("/{m_id}")
    public Result deleteCAdmin(@PathVariable String m_id){
        cAdminService.deleteOneCAdmin(m_id);
        return Result.success();
    }

    @DeleteMapping("/del")
    public Result deleteCAdmin(@RequestBody DelCAdminDto[] delCAdmin){
        cAdminService.deleteCAdmin(delCAdmin);
        return Result.success();
    }

}
